﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;
using System.Data.SqlClient;

namespace yfxt
{
    public partial class zy_cydy : Form
    {
        int currenindex;
        DataTable dt_tj = new DataTable();      //存储病区提交上的医嘱信息表
        DataTable dt_ksdm = new DataTable();   //存储科室代码表
        DataTable dt_fyfs = new DataTable();   //存储发药方式表
        DataTable dt_tj02 = new DataTable();    //存储病区提交医嘱详细信息
        DataTable dt_bqth = new DataTable();        //存储退回病区医嘱详细信息
        DataTable dt_hzfy = new DataTable();        //存储汇总发药医嘱详细信息
        public zy_cydy()
        {
            InitializeComponent();
        }
        public static int tjxh = 0;
        public static int int_cydy;
        public static int yzxh = 0;

        #region 主窗体载入
        private void zy_cydy_Load(object sender, EventArgs e)
        {
            string sqlstr1 = "select ksdm,ksmc from GY_KSDM where BQSY='Y'";
            string sqlstr2 = "select FYFS,FSMC from zy_fyfs";
            //获取数据表数据，将发药方式和病区分别添加到两个combobox中
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();

            dt1.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr1, null));
            dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr2, null));

            comboBox1.DataSource = dt2;
            comboBox1.DisplayMember = "fsmc";
            comboBox1.ValueMember = "fyfs";

            comboBox2.DataSource = dt1;
            comboBox2.DisplayMember = "ksmc";
            comboBox2.ValueMember = "ksdm";

            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;
        }
        #endregion

        #region tabcontrol关联事件 选中不同的发药tabpage，控件作相应的可用和不可用切换
        private void tabControl1_Click(object sender, EventArgs e)
        {
            //病人医嘱发药tabpage选中
            if (tabControl1.SelectedTab == tabPage1)
            {
                button2.Enabled = true;
                button3.Enabled = false;
                button4.Enabled = false;
                button7.Enabled = true;
                button8.Enabled = true;
                radioButton1.Enabled = true;
                radioButton2.Enabled = true;
                radioButton3.Enabled = true;
            }
            else if (tabControl1.SelectedTab == tabPage2)
            {
                button2.Enabled = true;
                button3.Enabled = false;
                button4.Enabled = false;
                button7.Enabled = false;
                button8.Enabled = true;
                radioButton1.Enabled = true;
                radioButton2.Enabled = true;
                radioButton3.Enabled = true;
            }
            else if (tabControl1.SelectedTab == tabPage4)
            {
                button2.Enabled = false;
                button3.Enabled = true;
                button4.Enabled = true;
                button7.Enabled = false;
                button8.Enabled = false;
                radioButton1.Enabled = false;
                radioButton2.Enabled = false;
                radioButton3.Enabled = false;
            }
        }
        #endregion

        #region cellclick 第一个数据窗体datagridview2的点击事件，将选中行的提交药品信息赋值给第二个窗体datagridview1
        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string sqlstr1, sqlstr2, sqlstr3;
            int tjxh;

            button2.Enabled = true;

            dt_tj02.Clear();
            dt_bqth.Clear();
            dt_hzfy.Clear();
            currenindex = dataGridView2.CurrentRow.Index;
            tjxh = int.Parse(dt_tj.Rows[currenindex]["tjxh"].ToString());
            SqlParameter[] sqlp = new SqlParameter[]
            {
                new SqlParameter("@tjxh",tjxh)
            };

            #region 获取信息到病区医嘱发药
            //根据所选中的列的条件信息查询数据库，将获取到的信息添加到datagridview1即病区医嘱发药tabpage中
            try
            {
                sqlstr1 = "select c.BRCH,c.BRXM,d.YPMC,b.kssj,b.fysl,b.yfgg,b.yfdw,b.ypdj,(b.fysl*b.ypdj) as zjje,e.CDMC,b.sypc,b.ypxh as '药品序号',b.jlxh as '记录序号',b.yzxh as '医嘱序号'" +
              "from BQ_TJ01 a,BQ_TJ02 b,ZY_BRRY c,YK_TYPK d,YK_CDDZ e,YK_YPCD f " +
              "where b.ZYH=c.zyh " +
              "and b.fybz=0 and b.lsyz=0 " +
              "and b.tjxh=@tjxh " +
              "and a.fybz=0 " +
              "and a.yzlx=3 " +
              "and a.tjxh=b.tjxh " +
              "and b.ypxh=f.ypxh " +
              "and b.ypxh=d.YPXH " +
              "and e.ypcd=f.ypcd " +
              " order by brch";
                dt_tj02.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr1, sqlp));
                dataGridView1.Columns[0].DataPropertyName = dt_tj02.Columns[0].ToString();  //床号
                dataGridView1.Columns[1].DataPropertyName = dt_tj02.Columns[1].ToString();  //病人姓名 
                dataGridView1.Columns[2].DataPropertyName = dt_tj02.Columns[2].ToString();  //药品名称
                dataGridView1.Columns[3].DataPropertyName = dt_tj02.Columns[3].ToString();  //开始时间
                dataGridView1.Columns[4].DataPropertyName = dt_tj02.Columns[4].ToString();  //发药数量
                dataGridView1.Columns[5].DataPropertyName = dt_tj02.Columns[5].ToString();  //规格
                dataGridView1.Columns[6].DataPropertyName = dt_tj02.Columns[6].ToString();  //单位
                dataGridView1.Columns[7].DataPropertyName = dt_tj02.Columns[7].ToString();  //单价
                dataGridView1.Columns[8].DataPropertyName = dt_tj02.Columns[8].ToString();  //金额
                dataGridView1.Columns[9].DataPropertyName = dt_tj02.Columns[9].ToString();  //产地
                dataGridView1.Columns[10].DataPropertyName = dt_tj02.Columns[10].ToString();    //用法
                //dataGridView5.Columns[11].DataPropertyName = dt_bqth.Columns[11].ToString();  //药品序号
                dataGridView1.DataSource = dt_tj02;
            }
            catch (Exception c)
            {
                MessageBox.Show(c.ToString());
            }
            #endregion

            #region 获取信息添加到退回单
            //根据所选中的列的条件信息查询数据库，将获取到的信息添加到datagridview4即退要单tabpage中ch/xm/ypmc/yf/gg/dw/fysl/ypdj/je/th
            try
            {
                sqlstr2 = "select c.BRCH,c.BRXM,d.YPMC,b.sypc,b.yfgg,b.yfdw,b.fysl,b.ypdj,(b.fysl*b.ypdj) as zjje,b.jlxh as '记录序号',b.yzxh as '医嘱序号' " +
                "from BQ_TJ01 a,BQ_TJ02 b,ZY_BRRY c,YK_TYPK d " +
                "where b.ZYH=c.zyh " +
                "and b.fybz=0 and b.lsyz=0 " +
                "and b.tjxh=@tjxh " +
                "and a.fybz=0 and yzlx=3 " +
                "and a.tjxh=b.tjxh " +
                "and b.ypxh=d.YPXH " +
                "order by brch";
                dt_bqth.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr2, sqlp));
                dataGridView5.Columns[0].DataPropertyName = dt_bqth.Columns[0].ToString();  //床号
                dataGridView5.Columns[1].DataPropertyName = dt_bqth.Columns[1].ToString();  //病人姓名 
                dataGridView5.Columns[2].DataPropertyName = dt_bqth.Columns[2].ToString();  //药品名称
                dataGridView5.Columns[3].DataPropertyName = dt_bqth.Columns[3].ToString();  //用法
                dataGridView5.Columns[4].DataPropertyName = dt_bqth.Columns[4].ToString();  //规格
                dataGridView5.Columns[5].DataPropertyName = dt_bqth.Columns[5].ToString();  //单位
                dataGridView5.Columns[6].DataPropertyName = dt_bqth.Columns[6].ToString();  //发药数量
                dataGridView5.Columns[7].DataPropertyName = dt_bqth.Columns[7].ToString();  //单价
                dataGridView5.Columns[8].DataPropertyName = dt_bqth.Columns[8].ToString();  //金额
                dataGridView5.DataSource = dt_bqth;
            }
            catch (Exception d)
            {
                MessageBox.Show(d.ToString());
            }
            #endregion

            #region 获取信息添加到汇总发药  //药品名称、规格、单位、药品产地、数量、单价、合计金额
            try
            {
                sqlstr3 = "select c.ypmc,b.yfgg,b.yfdw,d.cdmc,b.fysl,b.ypdj,(b.fysl*b.ypdj) as zjje,b.ypxh " +
                    "from bq_tj01 a," +
                    "bq_tj02 b," +
                    "yk_typk c," +
                    "yk_cddz d," +
                    "yk_ypcd e " +
                    "where a.yzlx=3 " +
                    "and a.fybz=0 " +
                    "and b.fybz=0 " +
                    "and b.lsyz=0 " +
                    "and b.tjxh=@tjxh " +
                    "and a.tjxh=b.tjxh " +
                    "and b.ypxh=e.ypxh " +
                    "and b.ypxh=c.ypxh " +
                    "and e.ypcd=d.ypcd " +
                    "order by c.ypmc ";
                dt_hzfy.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr3, sqlp));
                dataGridView3.Columns[0].DataPropertyName = dt_hzfy.Columns[0].ToString();
                dataGridView3.Columns[1].DataPropertyName = dt_hzfy.Columns[1].ToString();
                dataGridView3.Columns[2].DataPropertyName = dt_hzfy.Columns[2].ToString();
                dataGridView3.Columns[3].DataPropertyName = dt_hzfy.Columns[3].ToString();
                dataGridView3.Columns[4].DataPropertyName = dt_hzfy.Columns[4].ToString();
                dataGridView3.Columns[5].DataPropertyName = dt_hzfy.Columns[5].ToString();
                dataGridView3.Columns[6].DataPropertyName = dt_hzfy.Columns[6].ToString();
                dataGridView3.Columns[7].DataPropertyName = dt_hzfy.Columns[7].ToString();
                dataGridView3.DataSource = dt_hzfy;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            #endregion
        }
        #endregion

        #region  刷新按钮，将病区提交上的药品医嘱信息读取到datagridview中
        private void button1_Click(object sender, EventArgs e)
        {
            int fyfs = 0;               //获取combobox1的发药方式
            int ksdm = 0;               //获取combobox2的发药病区

            dt_tj.Clear();
            dt_fyfs.Clear();
            dt_ksdm.Clear();
            dt_tj02.Clear();
            dt_bqth.Clear();

            string sqlksmc = "select ksdm from gy_ksdm where ksmc='" + comboBox2.Text.ToString().Trim() + "'";        //获取科室代码语句
            string sqlfyfs = "select fyfs from zy_fyfs where fsmc='" + comboBox1.Text.ToString().Trim() + "'";        //获取发药方式语句

            dt_ksdm.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlksmc, null));
            dt_fyfs.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlfyfs, null));
            ksdm = int.Parse(dt_ksdm.Rows[0]["ksdm"].ToString());
            fyfs = int.Parse(dt_fyfs.Rows[0]["fyfs"].ToString());
            //测试messagebox
            // sqlstr获取病区提交医嘱sql语句
            string sqlstr = "select tjsj,(case when(fyfs=1) then '摆药' when(fyfs=2) then '发药' when (fyfs=3) then '处方用药' when (fyfs=4) then '大输液' when (fyfs=5) then '冷藏药品' when (fyfs=6) then '其他' when (fyfs=7) then '外用及其他' end ) as fyfs,(case when (tjbq=19) then '外一区' when(tjbq=20) then '外2区'when (tjbq=21) then '产科' when (tjbq=22) then '妇科' when (tjbq=23) then '内科' when (tjbq=24) then '儿科' when (tjbq=25) then '新生儿病区' end) as tjbq,tjgh,tjxh from bq_tj01 where fybz=0 and yzlx=3 and fyfs=@fyfs and tjbq=@ksdm and tjyf='" + mainform.yfsb + "' and CONVERT(varchar(25), tjsj, 121) like '" +
                        dateTimePicker1.Value.ToShortDateString() + "%' ";        //获取病区提交医嘱信息语句

            //发药方式、科室代码数组参数
            SqlParameter[] para_xz = new SqlParameter[]
            {
                new SqlParameter ("@fyfs",fyfs),
                new SqlParameter ("@ksdm",ksdm),
            };
            dt_tj.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, para_xz));
            //获取到的数据的列分别赋值给datagridview设定的列
            dataGridView2.Columns[1].DataPropertyName = dt_tj.Columns[0].ToString();
            dataGridView2.Columns[2].DataPropertyName = dt_tj.Columns[1].ToString();
            dataGridView2.Columns[3].DataPropertyName = dt_tj.Columns[2].ToString();
            dataGridView2.Columns[4].DataPropertyName = dt_tj.Columns[3].ToString();
            dataGridView2.Columns[5].DataPropertyName = dt_tj.Columns[4].ToString();
            dataGridView2.DataSource = dt_tj;

            tabControl1.SelectedIndex = 0;//将焦点移动到病区医嘱发药
            button2.Enabled = false;
        }
        #endregion

        #region 发药功能（修改发药标志）修改失败时做回滚，减库存
        private void button2_Click(object sender, EventArgs e)
        {
            string sqlstr1, sqlstr2, rollback1, rollback2, jkcstr, kcslstr;
            string date = System.DateTime.Now.ToString();       //发药时间、计费时间
            int tjxh;               //datagridview2提交序号
            int res1, res2;         //数据库操作返回影响行
            int currenindex = 0;     //dataGridView2焦点行计数
            int rowcount;       //datagridview1行计数
            float ypsl = 0;       //药品数量
            int ypxh = 0;       //药品序号
            DataTable dt_kcsl = new DataTable();        //存储库存查询结果datatable
            currenindex = dataGridView2.CurrentRow.Index;
            tjxh = int.Parse(dt_tj.Rows[currenindex]["tjxh"].ToString());
            SqlParameter[] para = new SqlParameter[] 
            {
                new SqlParameter("@tjxh",tjxh)
            };

            try
            {
                sqlstr1 = "update BQ_TJ01 set fybz=1 where yzlx=3 and tjxh=@tjxh ";
                rollback1 = "update BQ_TJ01 set fybz=0 where yzlx=3 tjxh=@tjxh";
                sqlstr2 = "update BQ_TJ02 set fybz=1,fygh='" + Program.ygbh + "',jfrq=CONVERT(char(25),'" + date + "',121),qrrq=CONVERT(char(25),'" + date + "',121),fyrq=CONVERT(char(25),'" + date + "',121) where tjxh=@tjxh  ";
                rollback2 = "update BQ_TJ02 set fybz=0 where tjxh=@tjxh";
                res1 = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr1, para);
                if (res1 == 0)
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback1, para);
                    MessageBox.Show("发药失败，刷新后请重新发药");
                }
                else
                {
                    res2 = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr2, para);
                    if (res2 == 0)
                    {
                        SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback1, para);
                        SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback2, para);
                        MessageBox.Show("数据库写入失败，刷新后请重新发药");
                    }
                    else
                    {
                        if (tabControl1.SelectedTab == tabPage1)
                        {
                            #region 操作医嘱发药page中的医嘱发药
                            //查询该笔提交医嘱中，是否有缺药的情况，若有，则不允许发药,如果库存充足，则每条记录减库存
                            for (rowcount = 0; rowcount < dataGridView1.RowCount; rowcount++)
                            {
                                ypxh = int.Parse(dt_tj02.Rows[rowcount]["药品序号"].ToString());                             //获取药品序号
                                kcslstr = "select ypsl from yf_kcmx where ypxh=@ypxh and yfsb='" + mainform.yfsb + "'";
                                SqlParameter[] kcslch = new SqlParameter[] 
                            {
                                 new SqlParameter("ypxh",ypxh)
                             };
                                SqlParameter[] kcgx = new SqlParameter[] 
                             {
                                  new SqlParameter("ypsl",ypsl),
                                  new SqlParameter("ypxh",ypxh)
                              };
                                dt_kcsl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, kcslstr, kcslch));
                                float back1, back2;     //库存药品数量、发药数量
                                back1 = float.Parse(dt_kcsl.Rows[rowcount]["ypsl"].ToString().Trim());
                                back2 = float.Parse(dt_tj02.Rows[rowcount]["fysl"].ToString().Trim());
                                ypsl = back1 - back2;
                                if (ypsl <= 0)
                                {
                                    MessageBox.Show("第" + rowcount + "条医嘱药品数量不足，发药失败，请改用其他等效药");
                                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback2, para);
                                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback1, para);
                                    break;
                                };
                                jkcstr = "update yf_kcmx set ypsl=@ypsl where yfsb='" + mainform.yfsb + "' and ypxh=@ypxh";
                                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, jkcstr, kcgx);

                            };

                            MessageBox.Show("发药成功");
                            #endregion
                        }
                        else
                        {
                            #region 操作汇总发药page中的医嘱发药
                            //查询该笔提交医嘱中，是否有缺药的情况，若有，则不允许发药,如果库存充足，则每条记录减库存
                            for (rowcount = 0; rowcount < dataGridView3.RowCount; rowcount++)
                            {
                                ypxh = int.Parse(dt_hzfy.Rows[rowcount]["ypxh"].ToString());                             //获取药品序号
                                kcslstr = "select ypsl from yf_kcmx where ypxh=@ypxh and yfsb='" + mainform.yfsb + "'";
                                SqlParameter[] kcslch = new SqlParameter[] 
                            {
                                 new SqlParameter("ypxh",ypxh)
                             };
                                SqlParameter[] kcgx = new SqlParameter[] 
                             {
                                  new SqlParameter("ypsl",ypsl),
                                  new SqlParameter("ypxh",ypxh)
                              };
                                dt_kcsl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, kcslstr, kcslch));
                                float back1, back2;     //库存药品数量、发药数量
                                back1 = float.Parse(dt_kcsl.Rows[rowcount]["ypsl"].ToString().Trim());
                                back2 = float.Parse(dt_hzfy.Rows[rowcount]["fysl"].ToString().Trim());
                                ypsl = back1 - back2;
                                if (ypsl <= 0)
                                {
                                    MessageBox.Show("第" + rowcount + "条医嘱药品数量不足，发药失败，请改用其他等效药");
                                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback2, para);
                                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback1, para);
                                    break;
                                };
                                jkcstr = "update yf_kcmx set ypsl=@ypsl where yfsb='" + mainform.yfsb + "' and ypxh=@ypxh";
                                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, jkcstr, kcgx);

                            };
                            button1_Click(sender, e);
                            MessageBox.Show("汇总发药成功");
                            #endregion
                        }

                    }

                }

            }
            catch (Exception f)
            {
                MessageBox.Show(f.ToString());
            }
        }
        #endregion

        #region 发药单打印
        private void button11_Click(object sender, EventArgs e)
        {
            int_cydy = 2;
            try
            {
                tjxh = int.Parse(dt_tj.Rows[currenindex]["tjxh"].ToString());
                zy_fy_rpt rpt = new zy_fy_rpt();
                //rpt = (zy_fy_rpt)this.Owner;
                rpt.ShowDialog();
            }
            catch
            {
                return;
            }
        }
        #endregion

        #region 全部退回病区
        private void button3_Click(object sender, EventArgs e)
        {
            string sqltystr1, sqltystr2;
            string rollback1, rollback2;
            int currenindex = 0;
            int tjxh;
            int res1, res2;
            currenindex = dataGridView2.CurrentRow.Index;
            tjxh = int.Parse(dt_tj.Rows[currenindex]["tjxh"].ToString());
            SqlParameter[] para = new SqlParameter[] 
            {
                new SqlParameter("@tjxh",tjxh)
            };
            sqltystr1 = "update bq_tj01 set fybz=3 where yzlx=3 and tjxh=@tjxh";
            sqltystr2 = "update bq_tj02 set fybz=3 where tjxh=@tjxh";
            rollback1 = "update bq_tj01 set fybz=0 where yzlx=3 and tjxh=@tjxh";
            rollback2 = "update bq_tj02 set fybz=0 where tjxh=@tjxh";
            res1 = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqltystr1, para);

            if (res1 == 0)
            {
                SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback1, para);
                MessageBox.Show("退回失败！请重新退回！");
            }
            else
            {
                res2 = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqltystr2, para);
                if (res2 == 0)
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback2, para);
                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, rollback1, para);
                    MessageBox.Show("退回失败！请重新退回！");
                }
                else
                {
                    MessageBox.Show("全部退回成功");
                }
            };
        }
        #endregion

        #region 退回病区
        private void button4_Click(object sender, EventArgs e)
        {
            string sqljlxh, sqltjxh;
            int res;
            int currenindex1, currenindex2;
            int jlxh, tjxh, rowcount;
            currenindex1 = dataGridView2.CurrentRow.Index;
            currenindex2 = dataGridView5.CurrentRow.Index;
            rowcount = dataGridView5.RowCount;
            tjxh = int.Parse(dt_tj.Rows[currenindex1]["tjxh"].ToString());
            jlxh = int.Parse(dt_tj02.Rows[currenindex2]["记录序号"].ToString());
            SqlParameter[] para1 = new SqlParameter[] 
            {
                new SqlParameter("@tjxh",tjxh),
                new SqlParameter("@jlxh",jlxh)
            };
            SqlParameter[] para2 = new SqlParameter[] 
            {
                new SqlParameter("tjxh",tjxh)
            };
            sqljlxh = "update bq_tj02 set fybz=3 where tjxh=@tjxh and jlxh=@jlxh";
            sqltjxh = "update bq_tj01 set fybz=3 where yzlx=3 and tjxh=@tjxh";
            res = int.Parse(SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqljlxh, para1).ToString());
            if (res != 0)
            {
                rowcount = rowcount - 1;
                if (rowcount == 0)
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqltjxh, para2);
                }
                MessageBox.Show("退回成功");
            }
            else
            {
                MessageBox.Show("退回失败，请重新尝试");
            }
        }
        #endregion

        #region 计费明细
        private void button7_Click(object sender, EventArgs e)
        {
            try 
            {
                int_cydy = 1;
                currenindex = dataGridView1.CurrentRow.Index;
                yzxh = int.Parse(dt_tj02.Rows[currenindex]["医嘱序号"].ToString());
                if (yzxh.ToString().Trim() == "") MessageBox.Show("没有医嘱信息");
                zy_fymx yfmx = new zy_fymx();
                yfmx.ShowDialog();
            }
            catch { return; }
            
        }
        #endregion

        #region 取消选中
        private void button8_Click(object sender, EventArgs e)
        {
            button1_Click(sender, e);
        }
        #endregion

        #region 退出
        private void button10_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
